import { Game, GameComponent } from "@sapi-game/main";
import { BuildWereWolfPlayerName } from "../func";
import { WereWolfMainState } from "../mainState/state";
import { WereWolfPlayer, WereWolfRole } from "../player";

export class WereWolfRoleActionbar extends GameComponent<WereWolfMainState> {
    override onAttach(): void {
        this.subscribe(Game.events.interval, () => {
            this.context.players.forEach((p) => {
                if (p.role)
                    p.actionbar(
                        `§6§l[玩家]${BuildWereWolfPlayerName(
                            p
                        )}    §6[身份]${this.getRoleText(p)}`
                    );
            });
        });
    }

    getRoleText(p: WereWolfPlayer) {
        switch (p.role) {
            case WereWolfRole.Seer:
                return "§b预言家";
            case WereWolfRole.Hunter:
                return "§e猎人";
            case WereWolfRole.Villager:
                return "§a平民";
            case WereWolfRole.Werewolf:
                const werewolves = this.context.players.filter(
                    (pp) => pp != p && pp.role == WereWolfRole.Werewolf
                );
                return (
                    "§c狼人     §6[同伙]" +
                    werewolves.map((pp) => pp.name).join(",")
                );
            case WereWolfRole.Witch:
                return "§5女巫";
        }
    }
}
